package main

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

//迭代法，用时32%，内存99%
func reverseList(head *ListNode) *ListNode {
	var prev *ListNode
	curr := head
	for curr != nil {
		next := curr.Next
		curr.Next = prev
		prev = curr
		curr = next
	}
	return prev
}

func main() {
	ListNode1 := ListNode{11, nil}
	listNode := ListNode{10, &ListNode1}
	fmt.Println(reverseList(&listNode))
}
